package com.example.hao.qq.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.hao.qq.Pojo.QingChiFan;
import com.bumptech.glide.Glide;
import com.example.hao.qq.R;
import com.example.hao.qq.Utils.DateUtils;

import java.util.List;

public class MyBaseAdapter extends BaseAdapter {
    private Context mcontext;
    private QingChiFan QingChiFan;
    List<QingChiFan.DataBean.ResultsBean> results ;


    public QingChiFan getQingChiFan() {
        notifyDataSetChanged();
        return QingChiFan;
    }

    public MyBaseAdapter(Context context, QingChiFan QingChiFan) {
        this.mcontext = context;
        this.QingChiFan = QingChiFan;
        results = QingChiFan.getData().getResults();
    }
    @Override
    public int getCount() {

        return  results == null? 0:results.size();
    }

    @Override
    public QingChiFan.DataBean.ResultsBean getItem(int position) {

        return results.get(position);
    }
    private static class ViewHolder{
        ImageView iv_icon;
        TextView tv_title;
        TextView tv_time;
        TextView tv_lastmsg;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = LayoutInflater.from(mcontext).inflate(R.layout.qcf_item, parent, false);
            ViewHolder viewHolder = new ViewHolder();
            viewHolder.iv_icon = convertView.findViewById(R.id.iv_icon);
            viewHolder.tv_title = convertView.findViewById(R.id.tv_title);
            viewHolder.tv_time = convertView.findViewById(R.id.tv_time);
            viewHolder.tv_lastmsg = convertView.findViewById(R.id.tv_lastmsg);

            convertView.setTag(viewHolder);
        }
        ViewHolder viewHolder = (ViewHolder) convertView.getTag();

        QingChiFan.DataBean.ResultsBean resultsBean = results.get(position);

        viewHolder.tv_title.setText(resultsBean.getEventDescription());
        viewHolder.tv_lastmsg.setText(resultsBean.getEventExpect());
        viewHolder.tv_time.setText(DateUtils.time(resultsBean.getCreateTime()));
        String url = resultsBean.getUser().getUserImageUrl();

        Glide.with(mcontext).load(url).into(viewHolder.iv_icon);
        return convertView;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }
}
